import Axios from "axios";
import $router from "@/router";
import URLConfig from "@/config";

const instance = Axios.create({
  baseURL: process.env.API_BASE_URL,
  headers: {
    "Content-Type": "multipart/form-data;charset=UTF-8"
  }
});

instance.interceptors.request.use(config => {
  let AUTH_TOKEN = window.localStorage["jd_safe_token"];
  config.headers.Authorization = AUTH_TOKEN; //'2018123135880949123'//AUTH_TOKEN;
  config.data = Object.assign({ Token: AUTH_TOKEN }, config.data);
  // config.headers.Authorization = '2018613admin8145120'
  return config;
});

instance.interceptors.response.use(data => {
  if (data.data.Code == "4000") {
    localStorage.clear();
    $router.replace({ name: "Login" });
  }

  return data;
});

export default instance;
